/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.TCube;

import entity.StakeholderBill;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import session.TX.SchedulerSBRemote;
import session.TX.StakeholderBillingSBRemote;

/**
 *
 * @author Randall Chia
 */
@ManagedBean (name = "billingMB")
@ViewScoped
public class stakeholderbillingMB {
    
    @EJB
    private SchedulerSBRemote schedulerBean;

    @EJB
    private StakeholderBillingSBRemote billingManager;
    
    private int selectedMonth;
    private int selectedYear;
    private StakeholderBill selectedBill;
    
    private boolean excludePaidBills;

    
    /** Creates a new instance of stakeholderbillingMB */
    public stakeholderbillingMB() {
    }
    
    
    
    
     public void setBillAsPaid(Long billID){
         getBillingManager().setBillAsPaid(billID);
         //selectedBill = null;
     }//--------------------------------------------------------------------------------------------------------------------------
     
     public List<StakeholderBill> retrieveBillsByMonth(){
         System.out.println("stakeholderbillingMB: Retrieving bills of Year: " + selectedYear + ", Month: " + selectedMonth);
         return getBillingManager().retrieveBillsByMonth(getSelectedMonth(), getSelectedYear(), isExcludePaidBills());
     }//--------------------------------------------------------------------------------------------------------------------------
     
     //This method is used to calculate the total amount payable/receivable, and then return it as a string
     public String displayOverallSubtotal(){
         if(selectedBill == null) return "";
         Double reimbursement = selectedBill.getReInbursement();
         Double bill = selectedBill.getSubTotal();
         Double amount = 0.0;
         
         if(bill > reimbursement){
             amount = bill - reimbursement;
             return "Total Amount Receivable from " + selectedBill.getStakeHolderName() + ": <br/>" + amount;
         }
         else if(bill < reimbursement){
             amount = reimbursement - bill;
             return "Total Amount Payable to " + selectedBill.getStakeHolderName() + ": \n" + amount;
         }
         else return "Billing charges are equal to transaction reimbursement";
     }
     
     
     
     
    //-----------------------------------------------------------------------------------------------------------------------------
    //Billing Controls
    public void startBilling(){
        schedulerBean.enableBilling();
    }
    public void stopBilling(){
        schedulerBean.disableBilling();
    }
    
    public void enableDemoBilling(){
        schedulerBean.enableDemoBilling();
    }
    public void disableDemoBilling(){
        schedulerBean.disableDemoBilling();
    }
    
    public String getBillingStatus(){
        return schedulerBean.getBillingStatus();
    }
    //-----------------------------------------------------------------------------------------------------------------------------
     
     
     
     
     
     
     
     
     
     

    /**
     * @return the billingManager
     */
    public StakeholderBillingSBRemote getBillingManager() {
        return billingManager;
    }

    /**
     * @param billingManager the billingManager to set
     */
    public void setBillingManager(StakeholderBillingSBRemote billingManager) {
        this.billingManager = billingManager;
    }

    /**
     * @return the selectedMonth
     */
    public int getSelectedMonth() {
        return selectedMonth;
    }

    /**
     * @param selectedMonth the selectedMonth to set
     */
    public void setSelectedMonth(int selectedMonth) {
        this.selectedMonth = selectedMonth;
    }

    /**
     * @return the selectedYear
     */
    public int getSelectedYear() {
        return selectedYear;
    }

    /**
     * @param selectedYear the selectedYear to set
     */
    public void setSelectedYear(int selectedYear) {
        this.selectedYear = selectedYear;
    }

    /**
     * @return the excludePaidBills
     */
    public boolean isExcludePaidBills() {
        return excludePaidBills;
    }

    /**
     * @param excludePaidBills the excludePaidBills to set
     */
    public void setExcludePaidBills(boolean excludePaidBills) {
        this.excludePaidBills = excludePaidBills;
    }

    /**
     * @return the selectedBill
     */
    public StakeholderBill getSelectedBill() {
        return selectedBill;
    }

    /**
     * @param selectedBill the selectedBill to set
     */
    public void setSelectedBill(StakeholderBill selectedBill) {
        this.selectedBill = selectedBill;
    }
    
    
    
}
